using CodePlex.DnD4eCampaignManager.DnD4e;
using NUnit.Framework;

namespace CodePlex.DnD4eCampaignManager.CampaignManagerTests.DnD4eTests
{
    [TestFixture]
    public class ExtensionMethodTests
    {
        [Test]
        public void ToModifierStringFormatsNegativeNumbersCorrectly()
        {
            const int negativeNumber = -1;
            Assert.AreEqual("-1", negativeNumber.ToModifierString());
        }

        [Test]
        public void ToModifierStringFormatsPositiveNumbersCorrectly()
        {
            const int positiveNumber = 1;
            Assert.AreEqual("+1", positiveNumber.ToModifierString());
        }

        [Test]
        public void ToModifierStringFormatsZerosCorrectly()
        {
            const int zero = 0;
            Assert.AreEqual("+0", zero.ToModifierString());
        }

        [Test]
        public void ToXmlStringReturnsXmlString()
        {
            const string expected =
                "<?xml version=\"1.0\" encoding=\"utf-7\"?>\r\n<XmlSerializableTestObject xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n\t<Name>name</Name>\r\n</XmlSerializableTestObject>";
            string actual = new XmlSerializableTestObject { Name = "name" }.ToXmlString();
            Assert.AreEqual(expected, actual);
        }

        [Test]
        public void TryParseToIntReturnsCorrectValueForIntString()
        {
            string integerAsString = "0";
            Assert.AreEqual(0, integerAsString.TryParseToInt());
            integerAsString = "5";
            Assert.AreEqual(5, integerAsString.TryParseToInt());
            integerAsString = "-12";
            Assert.AreEqual(-12, integerAsString.TryParseToInt());
        }

        [Test]
        public void TryParseToIntReturnsZeroForNonIntString()
        {
            string nonIntegerString = "";
            Assert.AreEqual(0, nonIntegerString.TryParseToInt());
            nonIntegerString = "abc";
            Assert.AreEqual(0, nonIntegerString.TryParseToInt());
            nonIntegerString = "2x";
            Assert.AreEqual(0, nonIntegerString.TryParseToInt());
        }

        public class XmlSerializableTestObject
        {
            public string Name { get; set; }
        }
    }
}